package com.cqc.designdemo02;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.ImageView;

/**
 * Created by cui on 2016/11/12.
 */

public class NewActivity extends AppCompatActivity {

    private ImageView iv;
    private Toolbar toolbar;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_new);

        findViews();
        initViews();
    }

    private void initViews() {
        ViewCompat.setTransitionName(iv, "transition");

        setSupportActionBar(toolbar);// android:theme="@style/Theme.AppCompat.NoActionBar"
        ActionBar actionBar = getSupportActionBar();
        actionBar.setDisplayHomeAsUpEnabled(true);//显示导航图标
        // actionBar.setHomeButtonEnabled(true);//可以不用加
    }

    private void findViews() {
        iv = (ImageView) findViewById(R.id.iv_activity_new);
        toolbar = (Toolbar) findViewById(R.id.toolbar);
    }

    //单击 actionbar的导航键 finish本页面
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {//actionbar的导航键
        if (item.getItemId() == android.R.id.home) {
            onBackPressed();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
